package com.zhyz.bookstore.service.impl;

import com.zhyz.bookstore.dao.ClientDao;
import com.zhyz.bookstore.dao.impl.ClientDaoImpl;
import com.zhyz.bookstore.entity.Book;
import com.zhyz.bookstore.entity.Favorite;
import com.zhyz.bookstore.entity.User;
import com.zhyz.bookstore.service.ClientService;

import java.util.List;
import java.util.UUID;

public class ClientServiceImpl implements ClientService {

    private ClientDao clientDao = new ClientDaoImpl();
    @Override
    public User login(String username, String password) {
        return clientDao.login(username, password);
    }

    @Override
    public boolean register(String username, String password, String name, String sex, String tel, String address) {
        User user = new User(UUID.randomUUID().toString(),username,password,name,sex,tel,address);
        return clientDao.register(user);
    }

    public List<Book> userbook(){
        return clientDao.userbook();
    }
    @Override
    public List<Book> getCategoryBook(String cid) {
        return clientDao.getCategoryBook(cid);
    }


    @Override
    public void personInformation(String username, String name, String sex, String tel, String address) {
        User user = new User(null, username, null, name, sex, tel, address);
        clientDao.personInformation(user);
    }

    @Override
    public void personPassword(String password, String username) {
        User user = new User(null, username, password, null, null, null, null);
        clientDao.personPassword(user);
    }

    @Override
    public void addfavorite(String userId, String bookId) {
        clientDao.addfavorite(UUID.randomUUID().toString(), userId, bookId);
    }

    public List<Favorite> findFavoriteByUserId(User user) {
        return clientDao.findFavoriteByUserId(user);
    }

    @Override
    public boolean findFavorite(String userId, String bookId) {
        return clientDao.findFavorite(userId, bookId);
    }

    @Override
    public void delFavorite(String bookId) {
        clientDao.delFavorite(bookId);
    }

    @Override
    public Book findBookById(String bookId) {
        return clientDao.findBookById(bookId);
    }

    public List<Book> search (String search){
        return clientDao.search(search);
    }
}
